<?php
namespace MemberUser\Controller;
use Common\Controller\MemberUserBaseController;
/**
 * 认证控制器
 */
class IndexController extends MemberUserBaseController{
 
    /**
     * 个人中心首页
     * 
     */
    public function index(){
    	$map['id']=$_SESSION['member_user'][id];
    	$data=M('MemberUsers')->where($map)->find();
    	$assign=array(
            	'site_name_tj'=>C('SITE_NAME_TJ'),
                'data'=>$data
                );
            $this->assign($assign);
    	$this->display();
    	
    }
    public function get_user_info(){
    	
    	//$this->ajaxreturn('admin/admin/index','info',1);
    	//ajax_Return("22222");
    	$map['id']='88';
    	$data=M('MemberUsers')->where($map)->find();
    	php_json($data,"成功啦",2);
    }
    public function login(){
        if(IS_POST){
        	
            // 做一个简单的登录 组合where数组条件
            
            if(IS_AJAX){
        		$map=I('post.');
            $map['password']=md5($map['password']);
            $data=M('MemberUsers')->where($map)->find();
            if (empty($data)) {
                $this->error('账号或密码错误');
            }else{
                $_SESSION['member_user']=array(
                    'id'=>$data['id'],
                    'username'=>$data['username'],
                    'avatar'=>$data['avatar']
                    );
                $this->success('登录成功、前往管理后台',U('MemberUser/Index/index'));
           		}
            } else{
            	
            $map=I('post.');
            $map['password']=md5($map['password']);
            $data=M('MemberUsers')->where($map)->find();
            if (empty($data)) {
                $this->error('账号或密码错误');
                
            }else{
                $_SESSION['member_user']=array(
                    'id'=>$data['id'],
                    'username'=>$data['username'],
                    'avatar'=>$data['avatar']
                    );
                $this->success('登录成功、前往管理后台',U('MemberUser/Index/index'));
            }
        }}else {
            $data=check_login() ? $_SESSION['member_user']['username'].'已登录' : '未登录';
            $assign=array(
            	'site_name_tj'=>C('SITE_NAME_TJ'),
                'data'=>$data
                );
            $this->assign($assign);
            $this->display();
        }
	}

    /**
     * 退出
     */
    public function logout(){
        session('member_user',null);
        $this->success('退出成功、前往登录页面',U('MemberUser/Index/login'));
    }

	public function message(){
		$this->display();
	}
	public function home(){
		$this->display();
		
	}
	public function set(){
		$this->display();
		
	}

}
